package com.niit.mall.api.fallback;

import com.niit.mall.api.client.ProductClient;
import com.niit.mall.api.domain.vo.ProductVO;
import com.niit.mall.common.api.CommonResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Slf4j
public class ProductClientFallbackFactory implements FallbackFactory<ProductClient> {
    @Override
    public ProductClient create(Throwable throwable) {
        return new ProductClient() {
            @Override
            public Long getCouponNum(Long userId) {
                log.error("查询优惠券数量失败", throwable);
                return 0L;
            }

            @Override
            public List<ProductVO> queryItemByIdsVO(List<Long> ids) {
                log.error("查询商品失败", throwable);
                return Collections.emptyList();
            }

            @Override
            public CommonResult<Void> reduceStock(Map<Long, Integer> productIdToQuantityMap) {
                log.error("调用 reduceStock 失败", throwable);
                return CommonResult.failed("调用 reduceStock 失败");
            }
        };
    }
}